<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var arr = [1, 2, 3]
    var newArr = arr.map(item => {
      return item * 2
    })
    console.log(newArr)
    // console.log(Array.isArray(arr))
    function map (arr, mapCallback) {
      if (!Array.isArray(arr) || arr.length === 0 || typeof mapCallback !== 'function') {
        return []
      } else {
        let result = []
        for (let i = 0, len = arr.length; i < len; i++) {
          // result[i] = mapCallback(arr[i], i)
          result.push(mapCallback(arr[i], i, arr))
        }
        return result
      }
    }
    var mapArr = map(arr, item => {
      return item * 2
    })
    console.log(mapArr)
  </script>
</body>
</html>